import { getMusicLyric } from '@/request/api/item'
import { createStore } from 'vuex'
import { getMusicList } from '@/request/api/home'
import { getPhoneLogin } from '@/request/api/home'
export default createStore({
  state: {
    playList:[
      {//播放列表
      name: "画",
      al:{
        id: 20339,
        name: "赵小雷",
        pic: 18876415625841068,
        picUrl: "https://p1.music.126.net/wldFtES1Cjnbqr5bjlqQbg==/18876415625841069.jpg",
        pic_str: "18876415625841069"
      },
      id:202369,
      ar:[{name: '赵雷'}],
    }
  ],
    playListIndex:0, //默认下标为0
    isbtnShow:true,//暂停按钮的显示
    detailShow:false,//歌曲详情页的显示
    lyricList:{},//歌词
    currentTime:0,//当前时间
    duration:0,//歌曲总时长
    isLogin:false,//判断是否登录
    isFooterMusic:true,//判断是否需要显示底部组件
    token:'',
    user:{}, //用户信息
  },
  mutations: {
    // 切换
    updateIsbtnShow:function(state,value){
      state.isbtnShow=value
    },
    // 添加
    pushPlayList:function(state,value){//更新默认列表
      state.playList.push(value)
    },
    // 更新playList
    updatePlayList:function(state,value){
      state.playList=value
      // console.log(state.playList)
    },
    // 更新playListIndex
    updatePlayListIndex:function(state,value){
      state.playListIndex=value
    },
    updateDetailShow:function(state){
      state.detailShow=! state.detailShow //只有关闭和打开两种状态切换，所以直接取反就行
    },
    updateLyricList:function(state,value){//歌词
      state.lyricList=value
    },
    updateCurrentTime:function(state,value){//当前时间
      // console.log(state.currentTime)
      state.currentTime=value
    },
    updateDuration:function(state,value){
      state.duration=value
    },
    updateIsLogin:function(state,value){
      state.isLogin=value
    },
    updateToken:function(state,value){
      state.token=value
      localStorage.setItem('token',state.token)
    },
    updateUser:function(state,value){
      state.user=value
    }
  },
  actions: {
    getLyric:async function(context,value){
      let res=await getMusicLyric(value)
      // console.log(res)
      context.commit('updateLyricList',res.data.lrc)
    },
    getLogin:async function(state,value){
      let res=await getPhoneLogin(value)
      // console.log(res)
      return res
    }
  },
  modules: {
  }
})
